
#include "util.h"
#include "dex-file.h"
//#include "class-defs.h"

void CDexFile::print()
{
	GetHeader()->print();

	for(int i=0;i<GetStringIdsSize();i++){
		printf("\nString ids [%d]:\n",i);
		GetStringIds()[i].print();
	}
	for(int i=0;i<GetTypeIdsSize();i++){
		printf("\nType ids [%d]:\n",i);
		GetTypeIds()[i].print();
	}
	for(int i=0;i<GetProtoIdsSize();i++){
		printf("\nProto ids [%d]:\n",i);
		GetProtoIds()[i].print();
	}
	for(int i=0;i<GetFieldIdsSize();i++){
		printf("\nField ids [%d]:\n",i);
		GetFieldIds()[i].print();
	}
	for(int i=0;i<GetMethodIdsSize();i++){
		printf("\nMethod ids [%d]:\n",i);
		GetMethodIds()[i].print();
	}
	char *p=(char *)GetClassDefsAddr();
	for(int i=0;i<GetClassDefsSize();i++){
		printf("\nClass defs [%d]:\n",i);
		((CDexClassDefs*)p)->print();
		p+=((CDexClassDefs*)p)->Size();
	}
	printf("\nData(%d bytes):\n",GetDataSize());
	print_mem32((char*)GetDataAddr(),0,GetDataSize());
	printf("\nLink data(%d bytes):\n",GetLinkDataSize());
	print_mem32((char*)GetLinkDataAddr(),0,GetLinkDataSize());

}
	
	
int CDexFile::sprint(char * buffer)
{
	int len;
	len=GetHeader()->sprint(buffer);

	for(int i=0;i<GetStringIdsSize();i++){
		len+=sprintf(buffer+len,"String ids [%d]:\n",i);
		len+=GetStringIds()[i].sprint(buffer+len);
	}
	for(int i=0;i<GetTypeIdsSize();i++){
		len+=sprintf(buffer+len,"Type ids [%d]:\n",i);
		len+=GetTypeIds()[i].sprint(buffer+len);
	}
	for(int i=0;i<GetProtoIdsSize();i++){
		len+=sprintf(buffer+len,"Proto ids [%d]:\n",i);
		len+=GetProtoIds()[i].sprint(buffer+len);
	}
	for(int i=0;i<GetFieldIdsSize();i++){
		len+=sprintf(buffer+len,"Field ids [%d]:\n",i);
		len+=GetFieldIds()[i].sprint(buffer+len);
	}
	for(int i=0;i<GetMethodIdsSize();i++){
		len+=sprintf(buffer+len,"Method ids [%d]:\n",i);
		len+=GetMethodIds()[i].sprint(buffer+len);
	}
	char *p=(char *)GetClassDefsAddr();
	for(int i=0;i<GetClassDefsSize();i++){
		len+=sprintf(buffer+len,"Class defs [%d]:\n",i);
		len+=((CDexClassDefs*)p)->sprint(buffer+len);
		p+=((CDexClassDefs*)p)->Size();
	}
	len+=sprintf(buffer+len,"Data(%d bytes):\n",GetDataSize());
	len+=sprint_mem32(buffer+len,0,(char*)GetDataAddr(),GetDataSize());
	len+=sprintf(buffer+len,"Link data(%d bytes):\n",GetLinkDataSize());
	len+=sprint_mem32(buffer+len,0,(char*)GetLinkDataAddr(),GetLinkDataSize());

	return len;
}
	
